package com.tbit.uqbike.webmanager.controller;

import com.tbit.uqbike.constant.enums.AccountSumStatEnum;
import com.tbit.uqbike.object.business.SugarPost;
import com.tbit.uqbike.object.pojo.vo.ScreenLineChartVO;
import com.tbit.uqbike.object.pojo.vo.ScreenPieVO;
import com.tbit.uqbike.object.value.LoginInfo;
import com.tbit.uqbike.object.view.NameObject;
import com.tbit.uqbike.object.view.sugar.ScreenResult;
import com.tbit.uqbike.service.base.ScreenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * sugar大屏接口（3.5新增大屏）
 *
 * @Author:BUGTian
 * @DATE: 2022/12/7
 */
@RestController
@RequestMapping("/sugar/screen")
public class ScreenController extends BaseController {

    @Autowired
    private ScreenService screenService;


    /**
     * 平台用户分布
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/userDistribution")
    public ScreenResult<List<ScreenPieVO>> userDistribution(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.userDistribution(login, sugarPost.getAccountIdList(), sugarPost.querys.brandId));
    }

    /**
     * 今日新增用户
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/todayNewUser")
    public ScreenResult<Long> todayNewUser(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.todayNewUser(login, sugarPost.getAccountIdList(), AccountSumStatEnum.NUMBER_OF_NEW_USERS.getDataType(), ScreenService.CNT, sugarPost.querys.brandId));
    }

    /**
     * 累计用户数
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/todayUser")
    public ScreenResult<Long> todayUser(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.singleResult(login, sugarPost.getAccountIdList(), AccountSumStatEnum.THE_TOTAL_NUMBER_OF_USERS.getDataType(), ScreenService.CNT, sugarPost.querys.brandId));
    }

    /**
     * 平台订单情况
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/orderCondition")
    public ScreenResult<List<ScreenPieVO>> orderCondition(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.orderCondition(login, sugarPost.getAccountIdList(), sugarPost.querys.brandId));
    }

    /**
     * 累计流水
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/totalFlowWater")
    public ScreenResult<Long> totalFlowWater(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.totalFlowWater(login, sugarPost.getAccountIdList(), sugarPost.querys.brandId) / 100);
    }

    /**
     * 交易数据
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/transactionData")
    public ScreenResult<List<ScreenPieVO>> transactionData(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.transactionData(login, sugarPost.getAccountIdList(), sugarPost.querys.brandId));
    }

    /**
     * 昨日同比增长
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/yesterdaySameRatio")
    public ScreenResult<Double> yesterdaySameRatio(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.yesterdaySameRatio(login, sugarPost.getAccountIdList(), sugarPost.querys.brandId));
    }

    /**
     * 昨日环比增长
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/yesterdayRingRatio")
    public ScreenResult<Double> yesterdayRingRatio(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.yesterdayRingRatio(login, sugarPost.getAccountIdList(), sugarPost.querys.brandId));
    }

    /**
     * 上月同比增长
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/lastMonthSameRatio")
    public ScreenResult<Double> lastMonthSameRatio(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.lastMonthSameRatio(login, sugarPost.getAccountIdList(), sugarPost.querys.brandId));
    }

    /**
     * 上月环比增长
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/lastMonthRingRatio")
    public ScreenResult<Double> lastMonthRingRatio(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.lastMonthRingRatio(login, sugarPost.getAccountIdList(), sugarPost.querys.brandId));
    }

    /**
     * 累计行驶里程
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/accumulatedMileage")
    public ScreenResult<String> accumulatedMileage(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.accumulatedMileage(login, sugarPost.getAccountIdList(), sugarPost.querys.brandId));
    }

    /**
     * 节能减排
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/reduceEmissions")
    public ScreenResult<String> reduceEmissions(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.reduceEmissions(login, sugarPost.getAccountIdList(), sugarPost.querys.brandId));
    }

    /**
     * 约等于种树xx棵
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/plantTrees")
    public ScreenResult<String> plantTrees(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.plantTrees(login, sugarPost.getAccountIdList(), sugarPost.querys.brandId));
    }


    /**
     * 投放车辆饼图
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/putOnMachinePieChart")
    public ScreenResult<List<ScreenPieVO>> putOnMachinePieChart(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.putOnMachinePieChart(login, sugarPost.getAccountIdList(), sugarPost.querys.brandId));
    }

    /**
     * 系统车辆总数
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/totalSystemMachine")
    public ScreenResult<Long> totalSystemMachine(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        return ScreenResult.success(screenService.singleResult(getLogin(request, sugarPost), sugarPost.getAccountIdList(), AccountSumStatEnum.TOTAL_NUMBER_OF_VEHICLES.getDataType(), ScreenService.CNT, sugarPost.querys.brandId));
    }

    /**
     * 运营车辆饼图
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/operationalMachinePieChart")
    public ScreenResult<List<ScreenPieVO>> operationalMachinePieChart(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.operationalMachinePieChart(login, sugarPost.getAccountIdList(), sugarPost.querys.brandId));
    }

    /**
     * 投放中车辆总数
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/totalPutOnMachine")
    public ScreenResult<Long> totalPutOnMachine(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        return ScreenResult.success(screenService.singleResult(getLogin(request, sugarPost), sugarPost.getAccountIdList(), AccountSumStatEnum.NUMBER_OF_VEHICLES_LAUNCHED.getDataType(), ScreenService.CNT, sugarPost.querys.brandId));
    }

    /**
     * 骑行和待租车辆饼图
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/ridingMachinePieChart")
    public ScreenResult<List<ScreenPieVO>> ridingMachinePieChart(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.ridingMachinePieChart(login, sugarPost.getAccountIdList(), sugarPost.querys.brandId));
    }

    /**
     * 可运营车辆总数
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/totalOperationalMachine")
    public ScreenResult<Long> totalOperationalMachine(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        return ScreenResult.success(screenService.singleResult(getLogin(request, sugarPost), sugarPost.getAccountIdList(), AccountSumStatEnum.NUMBER_OF_OPERATIONAL_VEHICLES.getDataType(), ScreenService.CNT, sugarPost.querys.brandId));
    }

    /**
     * 异常车辆饼图
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/abnormalMachinePieChart")
    public ScreenResult<List<ScreenPieVO>> abnormalMachinePieChart(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.abnormalMachinePieChart(login, sugarPost.getAccountIdList(), sugarPost.querys.brandId));
    }

    /**
     * 不可运营车辆总数
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/totalUnOperationalMachine")
    public ScreenResult<Long> totalUnOperationalMachine(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        Long totalOperationalMachine = screenService.singleResult(getLogin(request, sugarPost), sugarPost.getAccountIdList(), AccountSumStatEnum.NUMBER_OF_OPERATIONAL_VEHICLES.getDataType(), ScreenService.CNT, sugarPost.querys.brandId);
        Long totalPutOnMachine = screenService.singleResult(getLogin(request, sugarPost), sugarPost.getAccountIdList(), AccountSumStatEnum.NUMBER_OF_VEHICLES_LAUNCHED.getDataType(), ScreenService.CNT, sugarPost.querys.brandId);
        //投放-可运营
        return ScreenResult.success(totalPutOnMachine - totalOperationalMachine);
    }

    /**
     * 车辆电量饼图
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/machineBattery")
    public ScreenResult<List<NameObject>> machineBattery(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.machineBattery(login, sugarPost.getAccountIdList()));
    }

    /**
     * 车辆空闲时间饼图
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/machineIdle")
    public ScreenResult<List<NameObject>> machineIdle(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.machineIdle(login, sugarPost.getAccountIdList()));
    }

    /**
     * 告警信息概览
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/alarmMsg")
    public ScreenResult<List<ScreenPieVO>> alarmMsg(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.alarmMsg(login, sugarPost.getAccountIdList(), sugarPost.querys.brandId));
    }

    /**
     * 告警信息概览折线图
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/alarmMsgLineChart")
    public ScreenResult<ScreenLineChartVO> alarmMsgLineChart(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.alarmMsgLineChart(login, sugarPost.getAccountIdList(), sugarPost.querys.brandId));
    }

    /**
     * 总流水分布概况
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/pipelineDistribution")
    public ScreenResult<List<ScreenPieVO>> pipelineDistribution(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.pipelineDistribution(login, sugarPost.getAccountIdList(), sugarPost.querys.brandId));
    }

    /**
     * 运营区域收入排行
     *
     * @param sugarPost
     * @param request
     * @return
     */
    @PostMapping("/rankingOfOperatingIncome")
    public ScreenResult<ScreenLineChartVO> rankingOfOperatingIncome(@RequestBody SugarPost sugarPost, HttpServletRequest request) {
        LoginInfo login = getLogin(request, sugarPost);
        return ScreenResult.success(screenService.rankingOfOperatingIncome(login, sugarPost.getAccountIdList(), sugarPost.querys.brandId));
    }


}
